package my.mypool.core.http;

import my.mypool.core.PoolableParent;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpConnectionManager;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-9-21
 * Time: 10:22:27
 * To change this template use File | Settings | File Templates.
 */
public class PoolableHttp extends PoolableParent{
    private HttpConnection conn=null;
    public void destroy() throws Exception {
            conn.close();
    }

    public boolean validate() {
        return conn.isOpen();
    }

    public void activate() throws Exception {
        if(!conn.isOpen()){
            conn.open();
        }
    }

    public void passivate() throws Exception {

    }

    public void init(Object createParam) throws Exception {
        String[] address=((String)createParam).split(":");
        conn=new HttpConnection(address[0],Integer.parseInt(address[1]));
    }

    public HttpConnection getHttpConnection(){
        return conn;
    }
}
